from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware


def add_core_middleware(app: FastAPI) -> None:
    """
     添加跨域中间件

     :param app: FastAPI对象
     :return:
     """
    # 前端页面允许跨域访问
    origins = [
        'http://localhost:80',
        'http://127.0.0.1:80',
    ]
    app.add_middleware(
        CORSMiddleware,
        allow_origins=["*"],
        allow_credentials=True,
        allow_methods=["*"],
        allow_headers=["*"],
    )
